{{include file="common@layout/_meta_x-admin" /}}
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form method="post" class="layui-form">
            <input type="hidden" name="id" value="{{$content.id}}">
            <input type="hidden" name="type" value="{{$content.type}}">
            {{:widget('common/Form/upload',['详情图','pic',$content.pic,1, 'upload/system'])}}
            {{:widget('common/Form/richText',['详细内容','content',$content.content])}}
            {{volist name="content.specs" id="item"}}
                {{:widget('common/Form/photoCategory',[$item,$content])}}
            {{/volist}}
            {{:widget('common/Form/submit')}}
        </form>
    </div>
</div>
</body>
<script>
    function del_tr(obj) {
        var obj = $(obj);
        var id = obj.parent().parent().data('id');
        $.ajax({
            url:"delCate",
            type:"post",dataType:"json",
            data:{id:id},
            success:function(data){
                obj.parent().parent().remove()
            }
        })
    }
    function edit_tr(obj) {
        var obj = $(obj);
        var id = obj.parent().parent().data('id');
        $.ajax({
            url:"editCate",
            type:"post",dataType:"json",
            data:{id:id, field:obj.data("field"), value:obj.val()},
            success:function(data){
                layer.msg('更新成功')
            }
        })
    }
    function add_tr(obj){
        var obj = $(obj);
        $.ajax({
            url:"addCate",
            type:"post",dataType:"json",
            data:{type:obj.data("type"), content_type:"{{$content.type}}"},
            success:function(data){
                window.location.reload();return
                var data = data.data
                var html = '<tr data-id="'+data.id+'">\n' +
                    '           <td><input data-field="name" onblur="edit_tr(this)" type="text" value="'+data.name+'"  required="" lay-verify="required" maxlength="10"  autocomplete="off" class="layui-input"></td>\n' +
                    '           <td><a title="删除" onclick="del_tr(this)" href="javascript:;"><i class="iconfont">&#xe69d;</i></a></td>\n' +
                    '       </tr>'
                obj.parent().parent().parent().parent().append(html);
            }
        })
    }
    layui.use(['form','jquery'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //监听提交
        form.on('submit(submitForm)', function(data){
            getTinyMCE(data);
            //console.log(data)
            ajaxRequest('',data.field)
            return false;
        });
    });
</script>